local ADDON_NAME, ns = "oUF_BrethrenRF", BRF_NS

ns.orientation = {
	["VERTICAL"] = "VERTICAL",
	["HORIZONTAL"] = "HORIZONTAL",
}

ns.outline = {
	["None"] = "None",
	["OUTLINE"] = "OUTLINE",
	["THINOUTLINE"] = "THINOUTLINE",
	["OUTLINEMONO"] = "OUTLINEMONOCHROME",
}

local function updateFonts(object)
	object.groupText:SetFont(ns.db.fontPath, ns.db.fontsize-2, ns.db.outline)
	object.healthText:SetFont(ns.db.fontPath, ns.db.fontsize-2, ns.db.outline) 
	object.nameText:SetFont(ns.db.fontPath, ns.db.fontsize, ns.db.outline)
	
	if ns.db.fontShadow then
		object.groupText:SetShadowOffset(1,-1)
		object.healthText:SetShadowOffset(1,-1)
		object.nameText:SetShadowOffset(1,-1)
	else
		object.groupText:SetShadowOffset(0,0)
		object.healthText:SetShadowOffset(0,0)
		object.nameText:SetShadowOffset(0,0)
	end
	
	if ns.db.outline then
		if ns.db.fontShadow then
			object.nameText:SetPoint("LEFT",object.groupText,"RIGHT",-1,0)
		else
			object.nameText:SetPoint("LEFT",object.groupText,"RIGHT",0,0)
		end
	else
		if ns.db.fontShadow then
			object.nameText:SetPoint("LEFT",object.groupText,"RIGHT",2,0)
		else
			object.nameText:SetPoint("LEFT",object.groupText,"RIGHT",3,0)
		end
	end
	
end

local function updateIcons(object)
	object.Leader:SetSize(ns.db.iconsize, ns.db.iconsize)
	object.Assistant:SetSize(ns.db.iconsize, ns.db.iconsize)
	object.MasterLooter:SetSize(ns.db.iconsize, ns.db.iconsize)
	object.LFDRole:SetSize(ns.db.iconsize, ns.db.iconsize)
	object.ReadyCheck:SetSize(ns.db.iconsize, ns.db.iconsize)
	
	if ns.db.leadIcon then 
		 object.Leader:SetAlpha(1)
		 object.Assistant:SetAlpha(1)
		 object.MasterLooter:SetAlpha(1)
	else
		object.Leader:SetAlpha(0)
		 object.Assistant:SetAlpha(0)
		 object.MasterLooter:SetAlpha(0)
	end
	
	if ns.db.lfdIcon then
		object.LFDRole:SetAlpha(1)
	else
		object.LFDRole:SetAlpha(0)
	end
	
end

local borderDefGlow = {
	edgeFile = [=[Interface\AddOns\oUF_BrethrenRF\media\glowTex.tga]=], edgeSize = 5,
	bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=],
	insets = {left = 3, right = 3, top = 3, bottom = 3}
}
		
local borderDefThin = {
	bgFile = [=[Interface\AddOns\oUF_BrethrenRF\media\white.tga]=],
	insets = {top = -1, left = -1, bottom = -1, right = -1},
}

local function updateMiscColors(object)
	-- update border
	object.Border:ClearAllPoints()
	
	if ns.db.borderGlow then
		
		object.Border:SetBackdrop(borderDefGlow)
		object.Border:SetPoint("TOPLEFT", object, "TOPLEFT",-4, 4)
		object.Border:SetPoint("BOTTOMRIGHT", object, "BOTTOMRIGHT", 4, -4)
		object.Border:SetBackdropColor(ns.db.borderColor[1],ns.db.borderColor[2],ns.db.borderColor[3],0)
		object.Border:SetBackdropBorderColor(ns.db.glowColor[1],ns.db.glowColor[2],ns.db.glowColor[3])
		
	else
		
		object.Border:SetBackdrop(borderDefThin)
		object.Border:SetPoint("TOPLEFT", object, "TOPLEFT")
		object.Border:SetPoint("BOTTOMRIGHT", object, "BOTTOMRIGHT")
		object.Border:SetBackdropColor(ns.db.borderColor[1],ns.db.borderColor[2],ns.db.borderColor[3])
	end
	
	-- update background 
	object.BG:SetBackdropColor(ns.db.BackgroundColor[1], ns.db.BackgroundColor[2], ns.db.BackgroundColor[3])
end


local lockprint
local function updateObjects()
	if(InCombatLockdown()) then
		ns:RegisterEvent("PLAYER_REGEN_ENABLED")
		if not lockprint then
			lockprint = true
			print("Your in combat silly. Delaying updates until combat ends.")
		end
		return
	end

	for _, object in next, ns._Headers do
		object:SetScale(ns.db.scale)
	end
	
	for _, object in next, ns._Objects do
		object:SetSize(ns.db.width, ns.db.height)
		--object:SetScale(ns.db.scale)

		ns:UpdateHealthOptions(object.Health)
		ns:UpdatePowerOptions(object.Power)
		if UnitExists(object.unit) then
			object.Health:ForceUpdate()
			object.Power:ForceUpdate()
		end 
		
		updateMiscColors(object)
		updateFonts(object)
		updateIcons(object)
	end

	_G["oUF_BrethrenRFRaidFrame"]:SetSize(ns.db.width, ns.db.height)
	_G["oUF_BrethrenRFPetFrame"]:SetSize(ns.db.width, ns.db.height)
	_G["oUF_BrethrenRFMTFrame"]:SetSize(ns.db.width, ns.db.height)
	
end

function ns:PLAYER_REGEN_ENABLED()
	lockprint = nil
	updateObjects()

	ns:UnregisterEvent("PLAYER_REGEN_ENABLED")
end

local generalopts = {
	type = "group", name = "Size / Grouping", order = 1,
	args = {
		scale = {
			name = "Scale",
			type = "range",
			order = 2,
			desc = "Sets the scale for ALL BRF windows",
			min = 0.5,
			max = 2.0,
			step = .05,
			get = function(info) return ns.db.scale end,
			set = function(info,val) ns.db.scale = val; updateObjects() end,
		},
		width = {
			name = "Width",
			type = "range",
			order = 3,
			min = 10,
			max = 200,
			step = 1,
			get = function(info) return ns.db.width end,
			set = function(info,val) ns.db.width = val; updateObjects() end,
		},
		height = {
			name = "Height",
			type = "range",
			order = 4,
			min = 10,
			max = 200,
			step = 1,
			get = function(info) return ns.db.height end,
			set = function(info,val) ns.db.height = val; updateObjects() end,
		},
		sort = {
			name = "Grouping",
			type = "header",
			order = 5,
		},
		sortmem = {
			name = "Sort players by name",
			type = "toggle",
			order = 6,
			desc = "Sorts players by name rather than raid index, requires ReloadUI",
			get = function(info) if (ns.db.sortMethod == "NAME") then return true; else return false; end end,
			set = function(info,val)
				if(val == true) then
					ns.db.sortMethod = "NAME"
				else
					ns.db.sortMethod = "INDEX"
				end
			end,
		},

		horizontal = {
			name = "Horizontal groups",
			type = "toggle",
			order = 7,
			desc = "Dispays groups as rows instead of colummns, requires ReloadUI",
			get = function(info) return ns.db.HorizontalGroupGrowth end,
			set = function(info,val)
				if(val == true and (ns.db.growth ~= "UP" or ns.db.growth ~= "DOWN")) then
					ns.db.growthDirection = "UP"
				elseif(val == false and (ns.db.growth ~= "RIGHT" or ns.db.growth ~= "LEFT")) then
					ns.db.growthDirection = "RIGHT"
				end
				ns.db.HorizontalGroupGrowth = val; 
			end,
		},
		growth = {
			name = "Growth direction",
			type = "select",
			order = 8,
			desc = "specifies the direction additional columns or rows will be added. Requires ReloadUI.",
			values = function(info,val) 
				info = ns.db.growthDirection
				if not ns.db.HorizontalGroupGrowth then
					return { ["LEFT"] = "LEFT", ["RIGHT"] = "RIGHT", ["UP"] = "UP", ["DOWN"] = "DOWN" }
				else
					return { ["UP"] = "UP", ["DOWN"] = "DOWN" }
				end
			end,
			get = function(info) return ns.db.growthDirection end,
			set = function(info,val) ns.db.growthDirection = val; end,
		},
		splitGroups = {
			name = "Seperate raid groups",
			type = "toggle",
			desc = "seperates Groups from eachother for better distinction. This forces Units per group to be 5. Requres ReloadUI.",
			order = 9,
			get = function(info) return ns.db.splitGroups end,
			set = function(info,val) ns.db.splitGroups = val end,
		},
		units = {
			name = "Units per group",
			type = "range",
			desc = "Requires ReloadUI.",
			order = 10,
			min = 1,
			max = 40,
			step = 1,
			disabled = function(info) if ns.db.splitGroups then return true end end,
			get = function(info) return ns.db.numUnits end,
			set = function(info,val) ns.db.numUnits = val; end,
		},
		groups = {
			name = "Number of groups",
			type = "range",
			desc = "Requires ReloadUI.",
			order = 11,
			min = 1,
			max = 8,
			step = 1,
			get = function(info) return ns.db.numCol end,
			set = function(info,val) ns.db.numCol = val; end,
		},
		spacing = {
			name = "Space between units",
			type = "range",
			desc = "Requires ReloadUI.",
			order = 12,
			min = 0,
			max = 30,
			step = 1,
			get = function(info) return ns.db.spacing end,
			set = function(info,val) ns.db.spacing = val; end,
		},
	}
}

local SM = LibStub("LibSharedMedia-3.0", true)
local barsettingsopts = {
   type = "group", name = "Bar / Fonts", order = 2,
	args = {
		healthbar = {
			name = "Health Bar texture",
			type = "select",
			order = 2,
			dialogControl = "LSM30_Statusbar",
			values = SM:HashTable("statusbar"),
			get = function(info) return ns.db.healthTexture end,
			set = function(info, val) ns.db.healthTexture = val; ns.db.healthTexturePath = SM:Fetch("statusbar",val); updateObjects() end,
		},
		
		pb = {
			name = "Power Bar",
			type = "header",
			order = 3,
		},
		power = {
			name = "Enable PowerBars",
			type = "toggle",
			order = 4,
			get = function(info) return ns.db.powerbar end,
			set = function(info,val) ns.db.powerbar = val; updateObjects() end,
		},
		mana = {
			name = "Only show mana",
			type = "toggle",
			order = 5,
			get = function(info) return ns.db.onlyMana end,
			set = function(info,val) ns.db.onlyMana = val; updateObjects() end,
		},
		powerbar = {
			name = "PowerBar texture",
			type = "select",
			order = 6,
			dialogControl = "LSM30_Statusbar",
			values = SM:HashTable("statusbar"),
			get = function(info) return ns.db.powerTexture end,
			set = function(info, val) ns.db.powerTexture = val; ns.db.powerTexturePath = SM:Fetch("statusbar",val); updateObjects() end,
		},
		psize = {
			name = "PowerBar size",
			type = "range",
			order = 7,
			min = .02,
			max = .30,
			step = .02,
			get = function(info) return ns.db.powerbarsize end,
			set = function(info,val) ns.db.powerbarsize = val; updateObjects() end,
		},
		ft = {
			name = "Fonts",
			type = "header",
			order = 8,
		},
		font = {
			name = "Font",
			type = "select",
			order = 9,
			dialogControl = "LSM30_Font",
			values = SM:HashTable("font"),
			get = function(info) return ns.db.font end,
			set = function(info, val) ns.db.font = val; ns.db.fontPath = SM:Fetch("font",val); updateObjects() end,
		},
		fontsize = {
			name = "Font size",
			type = "range",
			order = 10,
			min = 8,
			max = 16,
			step = 1,
			get = function(info) return ns.db.fontsize end,
			set = function(info,val) ns.db.fontsize = val; updateObjects() end,
		},
		fontshadow = {
			name = "Font shadow",
			type = "toggle",
			order = 11,
			get = function(info) return ns.db.fontShadow end,
			set = function(info,val) ns.db.fontShadow = val; updateObjects() end,
		},
		fontoutline = {
			name = "Font outline",
			type = "select",
			order = 12,
			values = ns.outline,
			get = function(info) 
				if not ns.db.outline then
					return "None"
				else
					return ns.db.outline
				end
			end,
			set = function(info,val) 
				if val == "None" then
					ns.db.outline = nil
				else
					ns.db.outline = val
				end
				updateObjects()
			end,
		},
	}
}

local rangehealopts = {
	type = "group", name = "Range / Heal Prediction", order = 3,
	args = {
		oor = {
			name = "Out of range alpha",
			type = "range",
			order = 1,
			desc = "Requires ReloadUI.",
			min = 0,
			max = 1,
			step = .1,
			get = function(info) return ns.db.outsideRange end,
			set = function(info,val) ns.db.outsideRange = val end,
		},
		inr = {
			name = "in range alpha",
			type = "range",
			order = 2,
			desc = "Requires ReloadUI.",
			min = 0,
			max = 1,
			step = .1,
			get = function(info) return ns.db.inRange end,
			set = function(info,val) ns.db.inRange = val; end,
		},
		hp = {
			name = "Heal prediction",
			type = "header",
			order = 3,
		},
		healpre = {
			name = "Enable heal prediction",
			type = "toggle",
			order = 4,
			desc = "Requires ReloadUI.",
			get = function(info) return ns.db.healPrediction end,
			set = function(info,val) ns.db.healPrediction = val end,
		},
		healpretext = {
			name = "Incoming heal text",
			type = "toggle",
			order = 5,
			get = function(info) return ns.db.healPredictionText end,
			set = function(info,val) ns.db.healPredictionText = val end,
		},
		healover = {
			name = "Display overflow",
			type = "toggle",
			order = 6,
			get = function(info) return ns.db.healPredictionOverflow end,
			set = function(info,val) ns.db.healPredictionOverflow = val end,
		},
	}
}
local miscopts = {
	type = "group", name = "Miscellaneous", order = 4, 
	desc = "Most of these options require a reloadUI.",
	args = {
		wintog = {
			name = "Window toggles",
			type = "header",
			order = 1,
		},
		party = {
			name = "Show when in a party",
			type = "toggle",
			order = 2,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.party end,
			set = function(info,val) ns.db.party = val; end,
		},
		raid = {
			name = "Show when in a raid",
			type = "toggle",
			order = 3,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.raid end,
			set = function(info,val) ns.db.raid = val; end,
		},
		solo = {
			name = "Show when solo",
			type = "toggle",
			order = 4,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.solo end,
			set = function(info,val) ns.db.solo = val; end,
		},
		player = {
			name = "Show self in group",
			type = "toggle",
			order = 5,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.player end,
			set = function(info,val) ns.db.player = val; end,
		},
		pets = {
			name = "Show party/raid pets",
			type = "toggle",
			order = 6,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.pets end,
			set = function(info,val) ns.db.pets = val end,
		},
		MT = {
			name = "ManTanks window",
			type = "toggle",
			order = 7,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.MT end,
			set = function(info,val) ns.db.MT = val end,
		},
		Movespecial = {
			name = "Move boss special frame",
			type = "toggle",
			order = 8,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.moveBossSpecialFrame end,
			set = function(info,val) ns.db.moveBossSpecialFrame = val end,
		},
		fettog = {
			name = "feature toggles",
			type = "header",
			order = 9,
		},
		bglow = {
			name = "Glowing border",
			type = "toggle",
			order = 10,
			desc = "Changes the border to a glowing texture, set color in color tab.",
			get = function(info) return ns.db.borderGlow end,
			set = function(info,val) ns.db.borderGlow = val; updateObjects(); end,
		},
		tooltip = {
			name = "Show tooltip",
			type = "toggle",
			order = 11,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.showToolTip end,
			set = function(info,val) ns.db.showToolTip = val end,
		},
		roles = {
			name = "Show role icon",
			type = "toggle",
			order = 12,
			get = function(info) return ns.db.lfdIcon end,
			set = function(info,val) ns.db.lfdIcon = val; updateObjects() end,
		},
		leads = {
			name = "Show leader/assist icon",
			type = "toggle",
			order = 13,
			get = function(info) return ns.db.leadIcon end,
			set = function(info,val) ns.db.leadIcon = val; updateObjects() end,
		},
		buffcount = {
			name = "Show buff counter",
			type = "toggle",
			order = 14,
			get = function(info) return ns.db.displayBuffCounter end,
			set = function(info,val) ns.db.displayBuffCounter = val end,
		},
		groupnum = {
			name = "Show group numbers",
			type = "toggle",
			order = 15,
			get = function(info) return ns.db.displayGroupNumber end,
			set = function(info,val) ns.db.displayGroupNumber = val end,
		},
		nonclass = {
			name = "Show nonclass bars",
			type = "toggle",
			order = 16,
			desc = "Displays nonclass buff bars, Requires ReloadUI",
			get = function(info) return ns.db.displayNonClassBuffs end,
			set = function(info,val) ns.db.displayNonClassBuffs = val end,
		},
		topbar = {
			name = "Show boss debuff timer",
			desc ="This will show boss debuff timers on the top bar",
			type = "toggle",
			order = 17,
			desc = "Requires ReloadUI",
			get = function(info) return ns.db.UseTopBarForBossDebuffs end,
			set = function(info,val) ns.db.UseTopBarForBossDebuffs = val end,
		},
		hp = {
			name = "Feature sizes",
			type = "header",
			order = 18,
		},
		timerbarsize = {
			name = "Timerbar size",
			type = "range",
			order = 19,
			desc = "Requires ReloadUI",
			min = .02,
			max = .30,
			step = .02,
			get = function(info) return ns.db.timerBarSize end,
			set = function(info,val) ns.db.timerBarSize = val; updateObjects() end,
		},
		symbol = {
			name = "Top right indicator size",
			type = "range",
			order = 20,
			min = 8,
			max = 20,
			step = 1,
			get = function(info) return ns.db.symbolsize end,
			set = function(info,val) ns.db.symbolsize = val; updateObjects() end,
		},
		icon = {
			name = "Leader, raid, role icon size",
			type = "range",
			order = 21,
			desc = "Requires ReloadUI.",
			min = 8,
			max = 20,
			step = 1,
			get = function(info) return ns.db.iconsize end,
			set = function(info,val) ns.db.iconsize = val; updateObjects() end,
		},
		namelen = {
			name = "Max player name length",
			type = "range",
			order = 22,
			desc = "Requires ReloadUI",
			min = 3,
			max = 20,
			step = 1,
			get = function(info) return ns.db.nameLength end,
			set = function(info,val) ns.db.nameLength = val; end,
		},
		bossdecolamp = {
			name = "boss bar color multiplier",
			type = "range",
			order = 23,
			desc = "Requires ReloadUI",
			min = 0,
			max = 0.3,
			step = 0.01,
			get = function(info) return ns.db.bossDebuffBarColorAmplification end,
			set = function(info,val) ns.db.bossDebuffBarColorAmplification = val; end,
		},
		bossdecolamp = {
			name = "boss bar alpha",
			type = "range",
			order = 24,
			desc = "Requires ReloadUI",
			min = 0,
			max = 1,
			step = 0.1,
			get = function(info) return ns.db.bossDebuffBarAlpha end,
			set = function(info,val) ns.db.bossDebuffBarAlpha = val; end,
		},
	}
}

local coloropts = {
	type = "group", name = "Colors", order = 5,
	args = {
		HP = {
			name = "Health Bar",
			type = "header",
			order = 1,
		},
		classcol = {
			name = "Color health by class",
			type = "toggle",
			order = 2,
			desc = "Names will be displayed in the default text color (after ReloadUI or name update)",
			get = function(info) return ns.db.useClassColor end,
			set = function(info,val) ns.db.useClassColor = val; updateObjects(); 
			end,
		},
		hpcolorf = {
			name = "Full health bar color",
			type = "color",
			order = 3,
			hasAlpha = false,
			disabled = function(info) if ns.db.useClassColor then return true end end,
			get = function(info) return ns.db.healthTextureColor[1], ns.db.healthTextureColor[2], ns.db.healthTextureColor[3] end,
			set = function(info,r,g,b) ns.db.healthTextureColor[1], ns.db.healthTextureColor[2], ns.db.healthTextureColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		hpcolorh = {
			name = "Half health bar color",
			type = "color",
			order = 4,
			hasAlpha = false,
			disabled = function(info) if ns.db.useClassColor then return true end end,
			get = function(info) return ns.db.healthTextureColorMid[1], ns.db.healthTextureColorMid[2], ns.db.healthTextureColorMid[3] end,
			set = function(info,r,g,b) ns.db.healthTextureColorMid[1], ns.db.healthTextureColorMid[2], ns.db.healthTextureColorMid[3] = r,g,b;
				updateObjects(); 
			end,
		},
		hpcolore = {
			name = "Empty health bar color",
			type = "color",
			order = 5,
			hasAlpha = false,
			disabled = function(info) if ns.db.useClassColor then return true end end,
			get = function(info) return ns.db.healthTextureColorEnd[1], ns.db.healthTextureColorEnd[2], ns.db.healthTextureColorEnd[3] end,
			set = function(info,r,g,b) ns.db.healthTextureColorEnd[1], ns.db.healthTextureColorEnd[2], ns.db.healthTextureColorEnd[3] = r,g,b;
				updateObjects(); 
			end,
		},
		PP = {
			name = "Power Bar",
			type = "header",
			order = 6,
		},
		powerclass = {
			name = "Color power by class",
			type = "toggle",
			order = 7,
			get = function(info) return ns.db.powerclass end,
			set = function(info,val) ns.db.powerclass = val; updateObjects(); end,
		},
		ppcolor = {
			name = "Power bar color",
			type = "color",
			order = 8,
			hasAlpha = false,
			disabled = function(info) if ns.db.powerclass then return true end end,
			get = function(info) return ns.db.powerColor[1], ns.db.powerColor[2], ns.db.powerColor[3] end,
			set = function(info,r,g,b) ns.db.powerColor[1], ns.db.powerColor[2], ns.db.powerColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		ph = {
			name = "Heal Prediction",
			type = "header",
			order = 9,
		},
		phyc = {
			name = "Your heal bar Color",
			type = "color",
			order = 10,
			desc = "Requires ReloadUI",
			hasAlpha = true,
			get = function(info) return ns.db.predictedHealthColorYours[1], ns.db.predictedHealthColorYours[2], ns.db.predictedHealthColorYours[3], ns.db.predictedHealthColorYours[4] end,
			set = function(info,r,g,b,a) ns.db.predictedHealthColorYours[1], ns.db.predictedHealthColorYours[2], ns.db.predictedHealthColorYours[3], ns.db.predictedHealthColorYours[4] = r,g,b,a;
				updateObjects(); 
			end,
		},
		phtc = {
			name = "Their heal bar Color",
			type = "color",
			order = 11,
			desc = "Requires ReloadUI",
			hasAlpha = true,
			get = function(info) return ns.db.predictedHealthColorTheirs[1], ns.db.predictedHealthColorTheirs[2], ns.db.predictedHealthColorTheirs[3], ns.db.predictedHealthColorTheirs[4] end,
			set = function(info,r,g,b,a) ns.db.predictedHealthColorTheirs[1], ns.db.predictedHealthColorTheirs[2], ns.db.predictedHealthColorTheirs[3], ns.db.predictedHealthColorTheirs[4] = r,g,b,a;
				updateObjects(); 
			end,
		},
		txt = {
			name = "Text Colors",
			type = "header",
			order = 12,
			desc = "All of these in this section require a ReloadUI",
		},
		deftxtc = {
			name = "Default text color",
			type = "color",
			order = 13,
			desc = "Used for Name, Requires ReloadUI",
			hasAlpha = false,
			get = function(info) return ns.db.defaultTextColor[1], ns.db.defaultTextColor[2], ns.db.defaultTextColor[3] end,
			set = function(info,r,g,b) ns.db.defaultTextColor[1], ns.db.defaultTextColor[2], ns.db.defaultTextColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		aggcol = {
			name = "Aggro text color",
			type = "color",
			order = 14,
			desc = "Requires ReloadUI",
			hasAlpha = false,
			get = function(info) return ns.db.aggroColor[1], ns.db.aggroColor[2], ns.db.aggroColor[3] end,
			set = function(info,r,g,b) ns.db.aggroColor[1], ns.db.aggroColor[2], ns.db.aggroColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		hptc = {
			name = "Incoming heal text color",
			type = "color",
			order = 15,
			desc = "Requires ReloadUI",
			hasAlpha = false,
			get = function(info) return ns.db.predictedHealthTextColor[1], ns.db.predictedHealthTextColor[2], ns.db.predictedHealthTextColor[3] end,
			set = function(info,r,g,b) ns.db.predictedHealthTextColor[1], ns.db.predictedHealthTextColor[2], ns.db.predictedHealthTextColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		htcf = {
			name = "Full health text color",
			type = "color",
			order = 16,
			desc = "Used for missing health text, Requires ReloadUI",
			hasAlpha = false,
			disabled = function(info) if ns.db.useClassColor then return true end end,
			get = function(info) return ns.db.healthTextColor[1], ns.db.healthTextColor[2], ns.db.healthTextColor[3] end,
			set = function(info,r,g,b) ns.db.healthTextColor[1], ns.db.healthTextColor[2], ns.db.healthTextColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		htch = {
			name = "Half health text color",
			type = "color",
			order = 17,
			desc = "Used for missing health text, Requires ReloadUI",
			hasAlpha = false,
			disabled = function(info) if ns.db.useClassColor then return true end end,
			get = function(info) return ns.db.healthTextColorMid[1], ns.db.healthTextColorMid[2], ns.db.healthTextColorMid[3] end,
			set = function(info,r,g,b) ns.db.healthTextColorMid[1], ns.db.healthTextColorMid[2], ns.db.healthTextColorMid[3] = r,g,b;
				updateObjects(); 
			end,
		},
		htce = {
			name = "Empty health text color",
			type = "color",
			order = 18,
			desc = "Used for missing health text, Requires ReloadUI",
			hasAlpha = false,
			disabled = function(info) if ns.db.useClassColor then return true end end,
			get = function(info) return ns.db.healthTextColorEnd[1], ns.db.healthTextColorEnd[2], ns.db.healthTextColorEnd[3] end,
			set = function(info,r,g,b) ns.db.healthTextColorEnd[1], ns.db.healthTextColorEnd[2], ns.db.healthTextColorEnd[3] = r,g,b;
				updateObjects(); 
			end,
		},
		misccolors = {
			name = "Misc Colors",
			type = "header",
			order = 19,
		},
		backcol = {
			name = "Background color",
			type = "color",
			order = 20,
			hasAlpha = false,
			get = function(info) return ns.db.BackgroundColor[1], ns.db.BackgroundColor[2], ns.db.BackgroundColor[3] end,
			set = function(info,r,g,b) ns.db.BackgroundColor[1], ns.db.BackgroundColor[2], ns.db.BackgroundColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		bordcol = {
			name = "Border color",
			type = "color",
			order = 21,
			hasAlpha = false,
			get = function(info) return ns.db.borderColor[1], ns.db.borderColor[2], ns.db.borderColor[3] end,
			set = function(info,r,g,b) ns.db.borderColor[1], ns.db.borderColor[2], ns.db.borderColor[3] = r,g,b;
				updateObjects(); 
			end,
		},
		glowcol = {
			name = "Glowing border color",
			type = "color",
			order = 22,
			hasAlpha = false,
			get = function(info) return ns.db.glowColor[1], ns.db.glowColor[2], ns.db.glowColor[3] end,
			set = function(info,r,g,b) ns.db.glowColor[1], ns.db.glowColor[2], ns.db.glowColor[3] = r,g,b;
				updateObjects(); 
			end,
		},		
	}
}

local options = {
	type = "group", name = ADDON_NAME,
	args = {
		unlock = {
			name = "Toggle anchors",
			type = "execute",
			func = function() ns:Movable(); end,
			order = 1,
		},
		reload = {
			name = "ReloadUI",
			type = "execute",
			width = "half",
			desc = "Most options require a ReloadUI() to take effect.",
			func = function() ReloadUI(); end,
			order = 3,
		},
		restore = {
			name = "Defaults",
			desc = "Restores default settings",
			width = "half",
			type = "execute",
			confirm = true,
			func = function() ns:restoreDB(); end,
			order = 2,
		},
		general = generalopts,
		barsettings = barsettingsopts,
		rangeheal = rangehealopts,
		misc = miscopts,
		color = coloropts,
	}
}

local AceConfig = LibStub("AceConfig-3.0")
AceConfig:RegisterOptionsTable(ADDON_NAME, options)

local ACD = LibStub('AceConfigDialog-3.0')
ACD:AddToBlizOptions(ADDON_NAME, ADDON_NAME)

InterfaceOptions_AddCategory(ns.movableopt)
